{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy import signal\n",
    "from time import sleep\n",
    "from PIL import Image\n",
    "import numpy as np\n",
    "import string\n",
    "import shutil\n",
    "import base64\n",
    "import cv2\n",
    "import re\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Abort (auto)\n",
    "img = cv2.imread('3.4.png',0)\n",
    "scharr = np.array([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]])\n",
    "grad = signal.convolve2d(img, scharr)\n",
    "cv2.imwrite('4.1.png', grad)\n",
    "img = cv2.imread('4.1.png',0)\n",
    "#边缘检测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv2.imread('3.4.png',0)\n",
    "scharr = np.array([[3,-1],[-1,-1]])\n",
    "grad = signal.convolve2d(img, scharr)\n",
    "# grad = (grad!=510)*0\n",
    "cv2.imwrite('4.1.png', grad)\n",
    "img = cv2.imread('4.1.png',0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "True"
     },
     "metadata": {},
     "execution_count": 11
    }
   ],
   "source": [
    "sc2 = np.array([[1,1,1,1,1],[0,0,0,0,0]])\n",
    "grad = signal.convolve2d(img, sc2)\n",
    "#sc22 = np.array([[1,-1,-1,-1,1]])\n",
    "#grad2 = signal.convolve2d(grad, sc2)\n",
    "grad = (grad==1275)*255\n",
    "cv2.imwrite('4.2.png', grad)\n",
    "#horizontal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "True"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "sc3 = np.array([[0,1],[0,1],[0,1],[0,1],[0,1]])\n",
    "grad = signal.convolve2d(img, sc3)\n",
    "grad = (grad==1275)*255\n",
    "cv2.imwrite('4.3.png', grad)\n",
    "#vertical"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "True"
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "source": [
    "sc4 = np.array([[1,-1,-2],[-1,1,-1],[-2,-1,1]])\n",
    "grad = signal.convolve2d(img, sc4)\n",
    "grad = (grad>=510)*255\n",
    "cv2.imwrite('4.4.png', grad)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "True"
     },
     "metadata": {},
     "execution_count": 14
    }
   ],
   "source": [
    "sc5 = np.array([[-2,-1,2],[-1,1,-1],[2,-1,-2]])\n",
    "grad = signal.convolve2d(img, sc5)\n",
    "grad = (grad>=765)*255\n",
    "cv2.imwrite('4.5.png', grad)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6-final"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}